<?php
include_once 'checkAdmin.php';
include_once 'conn.php';
$userID = $_GET['userID'];
$action = $_GET['action'];
if(empty($userID) || !is_numeric($userID) || $userID <= 0){
    echo "<script>alert('参数错误');history.back();</script>";
    exit;
}
if($action !== '1' and $action !== '0'){
    echo "<script>alert('参数错误');history.back();</script>";
    exit;
}
$sql = "update userinfo set admin = '$action' where id = $userID";
$result = mysqli_query($conn,$sql);
$msg = $action ? '设置' : '取消';
$msg .= '管理员';
if($result){
    echo "<script>alert('{$msg}成功');location.href='admin.php';</script>";
}
else{
    echo "<script>alert('{$msg}失败');history.back();</script>";
}